/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on 07/09/2012, 10:06:32
 */
package Ventana;



import java.math.BigDecimal;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;


/**
 *
 * @author Fede
 */
public class VentanaV3 extends javax.swing.JFrame {
    private JScrollPane jScrollPane1;
    private JTable table;
   DefaultTableModel modeloTabla;

    /** Creates new form NewJFrame */
    public VentanaV3() {
        initComponents();
        this.crearTabla();
         this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }
    
    private void crearTabla()
    {
       //jScrollPane1 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable(){
            protected JTableHeader createDefaultTableHeader() {
                return new GroupableTableHeader(columnModel);
            }
      };
       
//        TableCellRenderer renderer = new RenderFila();
//        table.setDefaultRenderer( Object.class, renderer );
//        
        FormatoTabla formato = new FormatoTabla(); 
        table.setDefaultRenderer(Object.class, formato); 
//table.setDefaultRenderer(String.class, formato); 
//table.setDefaultRenderer(Integer.class, formato);
        
        
        
        jScrollPane1 = new javax.swing.JScrollPane();
        jScrollPane1.setViewportView(table);

        javax.swing.GroupLayout panelTablaLayout = new javax.swing.GroupLayout(panelTabla);
        panelTabla.setLayout(panelTablaLayout);
        panelTablaLayout.setHorizontalGroup(
            panelTablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
        );
        panelTablaLayout.setVerticalGroup(
            panelTablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelTabla, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTabla, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
        
   crearModeloTabla();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelBotones = new javax.swing.JPanel();
        btnSimular = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtCantidadEventos = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        panelTabla = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setExtendedState(3);

        panelBotones.setBorder(javax.swing.BorderFactory.createTitledBorder("Botones"));

        btnSimular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/iniciar.png"))); // NOI18N
        btnSimular.setText("Simular");
        btnSimular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimularActionPerformed(evt);
            }
        });

        jLabel1.setText("Cantidad de Evento a simular");

        txtCantidadEventos.setText("12");

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCantidadEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSimular)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(91, Short.MAX_VALUE))
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(txtCantidadEventos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnSimular)
                        .addComponent(jButton1)))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        panelTabla.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabla"));

        javax.swing.GroupLayout panelTablaLayout = new javax.swing.GroupLayout(panelTabla);
        panelTabla.setLayout(panelTablaLayout);
        panelTablaLayout.setHorizontalGroup(
            panelTablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 563, Short.MAX_VALUE)
        );
        panelTablaLayout.setVerticalGroup(
            panelTablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 380, Short.MAX_VALUE)
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados"));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 563, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 69, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelTabla, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTabla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSimularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimularActionPerformed
//
//        String texto = this.txtCantidadEventos.getText();
//        try
//        {
//            int cantidadEventos = Integer.parseInt(texto);
//            Simulacion s = new Simulacion(modeloTabla,cantidadEventos);
//        }
//        catch(NumberFormatException e)
//        {
//            if(texto.compareTo("")==0)
//            {
//                VentanaDeError.mostrarDialog("Erro al ingresar el dato", "Debe ingresar la cantidad de eventos a simular ", 2);
//                return;
//            }
//            
//            VentanaDeError.mostrarDialog("Erro al ingresar el dato", "La cantidad de eventos debe ser un número", 2);
//        }
        
        
        
    }//GEN-LAST:event_btnSimularActionPerformed

    private void crearModeloTabla()
    {
        modeloTabla = new DefaultTableModel();
    modeloTabla.setDataVector(new Object[][]{
      },
    new Object[]{"Ev\nento", "Reloj", "RND", "clientes", "llegada", "Cola Clientes", "Estado", "Atención","Atención", "Fin Atención", "Venta", "Venta", "Estado", "Atención","Atención", "Fin Atención", "Venta", "Venta", "Credito", "Contado", "Estado", "Fin Reparto"});
    

    
    this.table.setModel(modeloTabla);

    
    TableColumnModel cm = table.getColumnModel();
    ColumnGroup llegadaCLiente = new ColumnGroup("Llegada Cliente");
    llegadaCLiente.add(cm.getColumn(2));
    
    ColumnGroup tiemposClientes = new ColumnGroup("Llegada entre");
    tiemposClientes.add(cm.getColumn(3));
    tiemposClientes.setColumnMargin(WIDTH);
    
    llegadaCLiente.add(tiemposClientes);
    
    ColumnGroup proximaLLegada = new ColumnGroup("Proxima");
    proximaLLegada.add(cm.getColumn(4));
    
    llegadaCLiente.add(proximaLLegada);
           
    
    ColumnGroup vendedor1 = new ColumnGroup("Vendedor 1");
    vendedor1.add(cm.getColumn(6));
    
    ColumnGroup RNDtimpoAtencioV1 = new ColumnGroup("RND Tiempo");
    RNDtimpoAtencioV1.add(cm.getColumn(7));
    vendedor1.add(RNDtimpoAtencioV1);
    
    ColumnGroup tiempoAtencionV1 = new ColumnGroup("Tiempo de");
    tiempoAtencionV1.add(cm.getColumn(8));
    vendedor1.add(tiempoAtencionV1);
    
    ColumnGroup finAtencionV1 = new ColumnGroup("Tiempo");
    finAtencionV1.add(cm.getColumn(9));
    vendedor1.add(finAtencionV1);
    
    ColumnGroup RNDVentaV1 = new ColumnGroup("RND");
    RNDVentaV1.add(cm.getColumn(10));
    vendedor1.add(RNDVentaV1);
    
     ColumnGroup TipoVentaV1 = new ColumnGroup("Tipo");
    TipoVentaV1.add(cm.getColumn(11));
    vendedor1.add(TipoVentaV1);
    
    
            
    ColumnGroup vendedor2 = new ColumnGroup("Vendedor 2");
    vendedor2.add(cm.getColumn(12));
    
    ColumnGroup RNDtimpoAtencioV2 = new ColumnGroup("RND Tiempo");
    RNDtimpoAtencioV2.add(cm.getColumn(13));
    vendedor2.add(RNDtimpoAtencioV2);
    
    ColumnGroup tiempoAtencionV2 = new ColumnGroup("Tiempo de");
    tiempoAtencionV2.add(cm.getColumn(14));
    vendedor2.add(tiempoAtencionV2);
    
    ColumnGroup finAtencionV2 = new ColumnGroup("Tiempo");
    finAtencionV2.add(cm.getColumn(15));
    vendedor2.add(finAtencionV2);
    
    ColumnGroup RNDVentaV2 = new ColumnGroup("RND");
    RNDVentaV2.add(cm.getColumn(16));
    vendedor2.add(RNDVentaV2);
    
     ColumnGroup TipoVentaV2 = new ColumnGroup("Tipo");
    TipoVentaV2.add(cm.getColumn(17));
    vendedor2.add(TipoVentaV2);
    
    ColumnGroup deposito = new ColumnGroup("Depósito");
    deposito.add(cm.getColumn(18));
    deposito.add(cm.getColumn(19));
    
    ColumnGroup furgon = new ColumnGroup("Furgon");
    furgon.add(cm.getColumn(20));
    furgon.add(cm.getColumn(21));

    
    GroupableTableHeader header = (GroupableTableHeader)table.getTableHeader();
    header.addColumnGroup(llegadaCLiente);
    header.addColumnGroup(vendedor1);
    header.addColumnGroup(vendedor2);
    header.addColumnGroup(deposito);
    header.addColumnGroup(furgon);
    
    
    
    
    
       table.getColumnModel().getColumn(0).setPreferredWidth(180);
        table.getColumnModel().getColumn(1).setPreferredWidth(36);
        table.getColumnModel().getColumn(2).setPreferredWidth(35);
        table.getColumnModel().getColumn(3).setPreferredWidth(63);
        table.getColumnModel().getColumn(4).setPreferredWidth(81);
        table.getColumnModel().getColumn(5).setPreferredWidth(50);
        table.getColumnModel().getColumn(6).setPreferredWidth(61);
        table.getColumnModel().getColumn(7).setPreferredWidth(79);
        //table.getColumnModel().getColumn(8).setPreferredWidth(36);
        //table.getColumnModel().getColumn(9).setPreferredWidth(36);
        //table.getColumnModel().getColumn(10).setPreferredWidth(36);
        //table.getColumnModel().getColumn(11).setPreferredWidth(36);
        table.getColumnModel().getColumn(12).setPreferredWidth(61);
        table.getColumnModel().getColumn(13).setPreferredWidth(79);
        //table.getColumnModel().getColumn(14).setPreferredWidth(36);
        //table.getColumnModel().getColumn(14).setPreferredWidth(36);
        //table.getColumnModel().getColumn(14).setPreferredWidth(36);
        //table.getColumnModel().getColumn(14).setPreferredWidth(36);
        //table.getColumnModel().getColumn(14).setPreferredWidth(36);
        //table.getColumnModel().getColumn(14).setPreferredWidth(36);
        
    }
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
this.crearModeloTabla();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VentanaV3().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSimular;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel panelBotones;
    private javax.swing.JPanel panelTabla;
    private javax.swing.JTextField txtCantidadEventos;
    // End of variables declaration//GEN-END:variables
}

